package com.bcbim.authentication.menu.service;


import com.bcbim.authentication.menu.mapper.MenuMapper;
import com.bcbim.authentication_interface.menu.dao.MenuDAO;
import com.bcbim.authentication_interface.menu.dto.MenuDTO;
import com.bcbim.authentication_interface.menu.dto.ReductionMenuDTO;
import com.bcbim.authentication_interface.menu.dto.RoleAbilityDTO;
import com.bcbim.authentication_interface.menu.service.MenuService;
import com.bcbim.authentication_interface.menu.vo.MenuDetailVO;
import com.bcbim.authentication_interface.menu.vo.MenuVO;
import com.bcbim.authentication_interface.menu.vo.RoleMenuAbilityVO;
import com.bcbim.authentication_interface.menu.vo.TreeMenuVO;
import com.bcbim.common.sys.Code;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description: 菜单service实现类
 * @Author haoshuai
 * @Date 2020/9/27
 * @Version V1.0
 **/
@Service(timeout = 60 * 1000, group = "menu", version = "1.0.0")
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    /**
     * @param userId
     * @param applicationPlatform 应用平台 （1为PC，2为app,3为unity）
     * @param id
     * @Description: 根据用户ID获取菜单
     * @Param: userId 用户名ID
     * @Return: List<Menu>
     * @Author: zhangfan
     * @Date: 2021/5/17
     */
    @Override
    public List<MenuVO> listMenuApp(String userId, String applicationPlatform, String id) {
        return menuMapper.listMenuApp(userId,applicationPlatform, id);
    }

    /**
     * @Description: 根据登录用户名, 获取菜单
     * @Param: username 用户名
     * @param: applicationPlatform 应用平台 （1为PC，2为app,3为unity）
     * @Return: List<Menu>
     * @Author: ye
     * @Date: 2020/12/20
     */
    @Override
    public List<MenuVO> getMenuList(String username, String applicationPlatform) {
        return menuMapper.getMenuList(username, applicationPlatform);
    }

    /**
     * 新增菜单
     *
     * @return int
     * @Description
     * @Author XueHao
     * @Date 2021/8/18
     */
    @Override
    public int insertMenu(MenuDAO menuDAO) {
        return menuMapper.insertMenu(menuDAO);
    }

    /**
     * 获取菜单下拉列表
     *
     * @return List<Code>
     * @Description
     * @Author XueHao
     * @Date 2021/8/18
     */
    @Override
    public List<Code> selectMenu(MenuDTO menuDTO) {
        return menuMapper.selectMenu(menuDTO);
    }

    /**
     * @return int
     * @Description 更新菜单信息
     * @Author XueHao
     * @Date 2021/8/18
     */
    @Override
    public int updateMenu(MenuDAO menuDAO) {
        return menuMapper.updateMenu(menuDAO);
    }

    /**
     * @return int
     * @Description 删除菜单信息
     * @Author XueHao
     * @Date 2021/8/18
     */
    @Override
    public int removeMenu(MenuDAO menuDAO) {
        return menuMapper.updateMenu(menuDAO);
    }

    /**
     * @return int
     * @Description 判断是否有子级菜单
     * @Author haomeijie
     * @Date 2021/11/19
     */
    @Override
    public boolean getMenuCountByParentId(String parentId) {
        int count = menuMapper.getMenuCountByParentId(parentId);
        return count > 0 ? false : true;
    }

    /**
     * @return List<TreeMenuVO>
     * @Description 查询菜单信息列表
     * @Author XueHao
     * @Date 2021/8/18
     */
    @Override
    public List<TreeMenuVO> listMenu(MenuDTO menuDTO) {
        return menuMapper.listMenu(menuDTO);
    }

    /**
     * 查询菜单详情
     *
     * @param id id
     * @return MenuDetailVO
     * @author XueHao
     * @date 2021/12/1
     */
    @Override
    public MenuDetailVO getMenuDetail(String id) {
        return menuMapper.getMenuDetail(id);
    }

    /**
     * 查询父级菜单名称
     *
     * @param parentId parentId
     * @return String
     * @author XueHao
     * @date 2021/12/1
     */
    @Override
    public String getParentName(String parentId) {
        return menuMapper.getParentName(parentId);
    }

    /**
     * @Description: 根据用户id, 查询拥有权限菜单
     * @Param: userId 用户id
     * @Param: applicationPlatform 应用平台类型
     * @Return: List<RoleMenuVO>
     * @Author: haoshuai
     * @Date: 2021/7/7
     */
    @Override
    public List<RoleMenuAbilityVO> listRoleMenu(String userId, String applicationPlatform) {
        return menuMapper.listRoleMenu(userId, applicationPlatform);
    }

    /**
     * @Description: 根据用户id, 查询拥有权限功能
     * @Param: userId 用户id
     * @Param: applicationPlatform 应用平台类型
     * @Return: List<RoleMenuVO>
     * @Author: haoshuai
     * @Date: 2021/7/7
     */
    @Override
    public List<RoleAbilityDTO> listRoleAbility(String userId, String applicationPlatform) {
        return menuMapper.listRoleAbility(userId, applicationPlatform);
    }

    /**
     * 还原角色菜单：搜索没有修改之前的勾选的菜单id和功能按钮id
     *
     * @param query 查询参数:  角色id：roleId  菜单id：menuId
     * @return 返回没有修改之前的菜单id集合
     * @author wxc
     * @date 2021/10/21
     */
    @Override
    public List<String> reductionMenu(ReductionMenuDTO query) {
        return menuMapper.reductionMenu(query);
    }

    /**
     * @Description: 还原角色功能
     * @Param: ReductionMenuDTO
     * @Return: List<String>
     * @Author: ye
     * @Date: 2021/9/13
     */
    @Override
    public List<String> reductionMenuAbility(ReductionMenuDTO query) {
        return menuMapper.reductionMenuAbility(query);
    }
}
